package com.example.demorabbitmq.config;

import com.example.demorabbitmq.constant.Constants;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class DelayedConfig {

    @Bean("delayedQueue")
    public Queue delayedQueue() {
        return QueueBuilder.durable(Constants.DELAYED_QUEUE).build();
    }

    @Bean("delayedExchange")
    public Exchange delayedExchange() {
        return ExchangeBuilder.directExchange(Constants.DELAYED_EXCHANGE).durable(true).delayed().build();
    }

    @Bean("delayedExchangeBinding")
    public Binding delayedExchangeBinding(@Qualifier("delayedExchange") Exchange exchange, @Qualifier("delayedQueue") Queue queue) {
        return BindingBuilder.bind(queue).to(exchange).with("delayed").noargs();
    }
}
